package com.gukun.springboot.tdengine.pojo;


import cn.hutool.core.util.RandomUtil;
import com.gukun.springboot.tdengine.domain.enums.TagType;

import java.util.Objects;

public class TagData {

    /**
     * 时间戳
     */
    private Long ts;
    /**
     * 值
     */
    private String v;
    private Byte q;

    private String type;

    public TagData() {

    }

    public TagData(Long ts, String v, Byte q) {
        this.ts = ts;
        this.v = v;
        this.q = q;
    }


    public Long getTs() {
        return ts;
    }

    public void setTs(Long ts) {
        this.ts = ts;
    }

    public String getV() {
        return v;
    }

    public void setV(String v) {
        this.v = v;
    }

    public Byte getQ() {
        return q;
    }

    public void setQ(Byte q) {
        this.q = q;
    }


    public String getMockVal(TagType tagType) {
        String strV = "";
        switch (tagType) {
            case DOUBLE:
                strV = RandomUtil.randomDouble(6,1000000) + "";
                break;
            case FLOAT:
                strV = RandomUtil.randomDouble(2,10000) + "";;
                break;
            case INT:
                strV =RandomUtil.randomInt(0,100000000) + "";
                break;
            case BOOL:
                strV = RandomUtil.getRandom().nextBoolean() + "";
                break;
        }
        return strV;
    }



    @Override
    public String toString() {
        return "TagData{" +
                "ts=" + ts +
                ", value=" + v +
                ", quality=" + q +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TagData tagData = (TagData) o;

        if (!Objects.equals(ts, tagData.ts)) return false;
        if (!Objects.equals(v, tagData.v)) return false;
        return Objects.equals(q, tagData.q);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}
